import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  UpdateDateColumn,
  OneToMany,
} from "typeorm";
import { Article } from "./Article";

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  userName: string;

  @Column()
  email: string;

  @Column({ default: "" })
  passwordHash: string;

  @Column({ default: "active" })
  isActive: string;

  @CreateDateColumn({
    name: "create_time",
    nullable: true,
  })
  createTime: Date;

  @UpdateDateColumn({
    name: "update_time",
    nullable: true,
  })
  updateTime: Date | null;

  @Column({ default: "ordinary" })
  role: string;

  @OneToMany(() => Article, (article) => article.user, { eager: true })
  article: Article[];
}
